// @Desc:
// @CreateTime: 2020/10/8
package main

import (
    "github.com/gin-gonic/gin"
    "log"
    "mycrm.com/config"
    "mycrm.com/corntask"
    mlog "mycrm.com/log"
    "mycrm.com/module"
    "mycrm.com/router"
    "os"
)

// 项目初始化
func init() {
    projectDir, _ := os.Getwd()
    // 初始化配置信息
    config.InitConf(projectDir)

    // 初始化 log
    mlog.InitLogger()

    // 初始化数据库
    if err := module.InitDb(); err != nil {
        log.Fatal("module.InitDb() is failed, err: ", err)
    }

    // 初始化定时器
    if err := corntask.InitCronTask(); err != nil {
        log.Fatal("cronObj.AddFunc is failed, err: ", err)
    }
}


func main() {
    routerObj := gin.Default()
    router.Routers(routerObj)
    isProduction := config.Configs.LogConf.IsProduction
    var port string
    if isProduction {
        port = ":443"
    } else {
        port = ":9999"
    }
    if err := routerObj.Run(port); err != nil {
        log.Fatal("server run is failed, err:", err)
    }
}


